#include "main.h"
#include <time.h>
#include "lvgl.h"

static lv_obj_t * label1;
static lv_obj_t * label2;
static char strbuff[256];

void example_lvgl_demo_ui(lv_disp_t *disp)
{
    label1 = lv_label_create(lv_scr_act());
    lv_label_set_long_mode(label1, LV_LABEL_LONG_WRAP);
    lv_label_set_recolor(label1, true);
    sprintf(strbuff, "Prj1UFront\n%s\nby #0000ff masterraii@icloud.com#", TIMESTAMPER_VER);
    lv_obj_set_width(label1, EXAMPLE_LCD_V_RES);
    lv_obj_set_style_text_align(label1, LV_TEXT_ALIGN_LEFT, 0);
    lv_obj_align(label1, LV_ALIGN_TOP_LEFT, 0, 0);

    label2 = lv_label_create(lv_scr_act());
    lv_label_set_long_mode(label2, LV_LABEL_LONG_SCROLL_CIRCULAR);
    lv_obj_set_width(label2, EXAMPLE_LCD_V_RES);
    lv_label_set_recolor(label2, true);
    lv_label_set_text(label2, "It is a circularly scrolling text. ");
    lv_obj_align(label2, LV_ALIGN_BOTTOM_LEFT, 0, 0);
}

void UpdateUI(const char* str)
{
    static char statTxt[128];
    uint32_t time = esp_log_timestamp();
    sprintf(statTxt, "#ff00ff [%02lu:%02lu:%02lu]# %s",
        time / 60 / 60 / 1000,
        (time / 60 / 1000) % 60,
        (time / 1000) % 60,
        str);
    lv_label_set_text(label1, strbuff);
    lv_label_set_text(label2, statTxt);
}

void UpdatePanelStateLabel(const char* str)
{
    memset(strbuff, 0, sizeof(strbuff));
    memcpy(strbuff, str, strlen(str)); // argv[1] is infact a wild pointer
    printf("echoing: %s, len = %d\n", strbuff, strlen(strbuff));
}
